package com.mousycoder.mysql.config;

import com.mousycoder.mysql.interceptor.QueryInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author mousycoder
 * @version 1.0
 * @date 2022/3/23 4:03 PM
 */
@Configuration
public class MyBatisConfig {

    @Resource
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct
    public void addInterceptor() {
        QueryInterceptor queryInterceptor = new QueryInterceptor();
        sqlSessionFactoryList.forEach(sqlSessionFactory -> sqlSessionFactory.getConfiguration().addInterceptor(queryInterceptor));
    }

}
